// pages/getRbox/getRbox.js
var util = require("../../utils/util.js");
var qcloud = require('../../vendor/wafer2-client-sdk/index');
var config = require('../../config');
Page({

  /**
   * 页面的初始数据
   */
  data: {
    orderAddressId:''
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.setData({
      orderAddressId: options.address_id,
    });
    wx.setNavigationBarTitle({
      title: '共享智能箱',
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },
  movetoSendBox: function () {
    wx.navigateTo({
      url: '../carryBox/carryBox?address_id=' + this.data.orderAddressId,
    })
  },
  movetoBackBox: function () {
    var that = this;
    var _uid = wx.getStorageSync("userInfo").userInfo.uid;
    var _address_id = that.data.orderAddressId;
    console.log(_address_id);
    const requestTask = wx.request({
      url: 'https://boxapi.supergk.com/server/user/call_courier',
      data: util.json2Form({
        uid: _uid,
        type: "2",//归还箱子
        address_id: _address_id,
      }),
      method: "POST",
      header: {
        "Content-Type": "application/x-www-form-urlencoded"
      },
      success: function (res) {
        console.log(res);
        if (res.data.code == "0") {
          console.log(res.data.msg)
          // 存储我的快递召唤信息
          that.setData({
            orderStatus: res.data
          })
          // 存储我的快递召唤信息到本地
          wx.setStorage({
            key: 'orderStatus',
            data: {
              orderStatus: res.data,
            },
            success: function (e) {
              console.log("存储用户快递召唤信息成功")
              // util.showModel('召唤快递', error)
              wx.showModal({
                title: '召唤快递',
                content: res.data.msg,
                showCancel: false,
                success: function (res) {
                  if (res.confirm) {
                    wx.navigateTo({
                      url: '../index/index',
                    })
                  }
                }
              })
            },
          })
        }

      }
    })
  }
})